﻿using System;

namespace TLang.Ast
{
    using Values;

    public class Name : Node
    {
        public readonly String Id;


        public Name(String id, String file, int start, int end, int line, int col) : base(file, start, end, line, col)
        {
            this.Id = id;
        }

        /**
         * Generate a name without location info
         */
        public static Name GenName(String id)
        {
            return new Name(id, null, 0, 0, 0, 0);
        }

        public override Value Interp(Scope s)
        {
            return s.Lookup(Id);
        }

        public override Value Typecheck(Scope s)
        {
            Value v = s.Lookup(Id);
            if (v != null)
            {
                return v;
            }
            else
            {
                Util.Abort(this, "unbound variable: " + Id);
                return Value.VOID;
            }
        }


        public override String ToString()
        {
            return Id;
        }
    }
}
